<style lang="scss" scoped="">
  @import '../../styles/variables';

</style>
<template>
  <div>
    <div style="padding:10px;">
      <template>
        <el-table
          :data="nodeList"
          border
          style="width: 100%">
          <el-table-column
            prop="nodeName"
            label="节点名称">
          </el-table-column>
          <el-table-column
            prop="times"
            label="心跳超时次数">
          </el-table-column>

        </el-table>

        <div class="pagination">
          <el-pagination
            background
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="1"
            :page-sizes="[10, 50, 100]"
            :page-size="filter.pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="nodeCount">
          </el-pagination>
        </div>
      </template>
    </div>
  </div>
</template>
<script>
  import utils from '@/utils/utils';
  import {heartBeatService} from '@/api/index';
  import {mapGetters} from 'vuex';

  export default {
    data() {
      return {
        filter: {
          pageNo: 1,
          pageSize: 10,
          start: 0
        },
        nodeCount: 0,
        nodeList: []
      };
    },
    computed: {},
    watch: {
      'filter': {
        handler: function () {
          this.getNodeList();
        },
        deep: true,
        immediate: true
      }
    },
    components: {},
    methods: {
      handleCurrentChange(currentPageNo) {
        this.filter.start = (currentPageNo - 1) * this.filter.pageSize;
      },
      handleSizeChange(pageSize) {
        this.filter.pageSize = pageSize;
        localStorage.setItem('headBeat-page-size', pageSize);

      },
      getNodeList() {
        heartBeatService.getPage(this.filter).then(res => {
          this.nodeCount = res.data.total;
          this.nodeList = res.data.rows;
        });
      }
    },
    mounted() {
    },
    created() {
      let oldPageSize = localStorage.getItem('headBeat-page-size');
      if (!oldPageSize) {
        oldPageSize = 10;
      }
      this.filter.pageSize = Math.floor(oldPageSize);
    }
  };
</script>
